package com.example.smartcity_poverty.ui.AllService.LogisticsQuery.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.ServiceBean.LogisticsQueryBean.LqTouSuListModel
import com.example.smartcity_poverty.logic.util.Util.show
import com.example.smartcity_poverty.ui.AllService.LogisticsQuery.adapter.LqTouSuListAdapter
import kotlinx.android.synthetic.main.activity_lq_dan_hao.*
import kotlinx.android.synthetic.main.activity_lq_me_tou_su_activity.*
import kotlinx.coroutines.Dispatchers

/**
 * 以往个人投诉列表页
 */
class LqMeTouSuActivityActivity : AppCompatActivity() {

    // 物流公司id
    private var id: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_lq_me_tou_su_activity)
        title = "投诉"
        id = intent.getStringExtra("id")


        // 点击投诉按钮进入投诉界面
        lqMeTouSuAdd.setOnClickListener {
            startActivity(Intent(this, LqTouSuAddActivity::class.java).putExtra("id", id))
        }

    }


    private val arrayList = ArrayList<LqTouSuListModel.RowsBean>()
    override fun onStart() {
        super.onStart()
        coroutine(Dispatchers.Main) {
            api.getLqTouSuListAll(getToken()).apply {
                if (this.code == 200) {
                    arrayList.clear()
                    arrayList.addAll(this.rows!!)
                    runOnUiThread {
                        lqTouSuListRv.apply {
                            this.isNestedScrollingEnabled = false
                            this.adapter = LqTouSuListAdapter(arrayList, R.layout.re_lq_tousu_list)
                            this.layoutManager = LinearLayoutManager(context)
                            this.adapter?.notifyItemChanged(arrayList.size)
                        }
                    }
                } else runOnUiThread { this.msg?.show() }
            }
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}